package org.lgiavedoni.android.franq.httpserver;

import java.util.HashMap;
import java.util.Map;

import org.apache.velocity.VelocityContext;
import org.lgiavedoni.android.franq.core.httpserver.HttpPageController;
import org.lgiavedoni.android.franq.core.service.ServiceManager;

public class ServicesPage extends HttpPageController {

	@Override
	public String getPath() {
		return "services.html";
	}

	@Override
	public VelocityContext actionDefault(VelocityContext context) {
		context.put("list", ServiceManager.inst.getAllServices());
		return context;

	}

	public VelocityContext actionStart(VelocityContext context, HashMap<String, String> params) {
		ServiceManager.inst.getService(params.get("service")).start();
		return actionDefault(context);
	}

	public VelocityContext actionStop(VelocityContext context, HashMap<String, String> params) {
		ServiceManager.inst.getService(params.get("service")).stop();
		return actionDefault(context);
	}

	public VelocityContext actionEnable(VelocityContext context, HashMap<String, String> params) {
		ServiceManager.inst.getService(params.get("service")).setEnable(true);
		return actionDefault(context);
	}

	public VelocityContext actionDisable(VelocityContext context, HashMap<String, String> params) {
		ServiceManager.inst.getService(params.get("service")).setEnable(false);
		return actionDefault(context);
	}

	@Override
	public String getTemplateName(Map<String, String> params) {
		return "services.html";
	}

}
